package com.gdufe.firesafe.controller;

import com.gdufe.firesafe.annotation.NeedAdmin;
import com.gdufe.firesafe.model.entity.NoticeEntity;
import com.gdufe.firesafe.service.NoticeService;
import com.gdufe.firesafe.utils.PageUtils;
import com.gdufe.firesafe.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 公告表
 *
 * @author Liu
 * @email
 * @date 2024-03-26 16:36:35
 */
@RestController
@RequestMapping("notice/notice")
public class NoticeController {
    @Autowired
    private NoticeService noticeService;
//
//    /**
//     * 获取业主或检查员的公告
//     */
//    @GetMapping("/getNotice")
//    public R getNotice(){
//        UserEntity currentUser = TokenUtils.getCurrentUser();
//        return R.ok().put("data", noticeService.getNotice(currentUser.getId()));
//    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = noticeService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		NoticeEntity notice = noticeService.getById(id);

        return R.ok().put("notice", notice);
    }

    /**
     * 保存
     */
    @NeedAdmin
    @RequestMapping("/save")
    public R save(@RequestBody NoticeEntity notice){
		noticeService.save(notice);
        return R.ok();
    }

    /**
     * 修改
     */
    @NeedAdmin
    @RequestMapping("/update")
    public R update(@RequestBody NoticeEntity notice){
		noticeService.updateById(notice);

        return R.ok();
    }

    /**
     * 删除
     */
    @NeedAdmin
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		noticeService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
